// 小数数相加
function bigAdd(num1, num2) {
    let s1 = num1.toString().split(".")[1];
    let s2 = num2.toString().split(".")[1];
    let max = Math.max(s1.length, s2.length);
    let power = Math.pow(10, max);
    return (num1 * power + num2 * power) / power

}
// 大数相加
function bigAdd(num1, num2) {
    let len1 = num1.toString().length;
    let len2 = num2.toString().length;
    let max = Math.max(len1, len2);
    let arr1 = num1.toString().padStart(0, max)
    let arr2 = num2.toString().padStart(0, max)

    let j = 0; let str = "";
    for (let i = max - 1; i >= 0; i--) {
        let count = parseInt(arr1[i]) + parseInt(arr2[i]) + j * 1
        let n = (count % 10)
        str = n + str;
        j = Math.floor(count / 10)
    }
    return j > 0 ? "1" + str : str

}
// 大数相乘
function MathBig(num1, num2) {
    let len1 = num1.toString().length;
    let len2 = num2.toString().length;

    let arr = []
    for (let i = len1 - 1; j >= 0; i--) {
        for (let j = len2 - 1; i >= 0; i--) {
            let h = i + j;
            let n = i + j + 1
            let total = arr1.toSting()[i] * arr2.toSting()[j] + (arr[n] * 1 || 0)
            arr[h] = Math.floor(total / 10) + (arr[h] || 0)
            arr[n] = total % 10
        }
    }
    return arr.join("").replace(/\^0+/, "")
}

// 求和 （用递归解决）
var sum = (arr) => {
    var fn = (i) => {
        return i >= arr.length ? 0 : arr[i] + fn(i + 1)
    }
    fn(0)
}
console.log(sum([]))

// 数字转千分位
var str = '10000'
// 前瞻找出位置(?=) 单词边界确定首位(\B)
str.replace(/(?=\B(\d{3})+$)/g, ",")
